# -*- encoding=utf8 -*-
__author__ = "yupf"

from airtest.core.api import *

# auto_setup(__file__)


from poco.drivers.ios import iosPoco


def login(poco: iosPoco, user_name: str, password: str):
    start_app("com.mttnow.iphone.easyjet")
    wait(Template(r"tpl1685280881061.png", record_pos=(0.048, -0.151), resolution=(1242, 2208)))
    touch(Template(r"tpl1685280891033.png", record_pos=(0.428, -0.79), resolution=(1242, 2208)))
    if exists(Template(r"tpl1685282621781.png", record_pos=(0.018, -0.362), resolution=(1242, 2208))):
        poco('Sign out', type='Button').click()

        poco('Yes', type='Button').wait_for_appearance()
        poco('Yes', type='Button').click()
        sleep(5)

    if exists(Template(r"tpl1685280944396.png", record_pos=(-0.009, -0.495), resolution=(1242, 2208))):
        touch(Template(r"tpl1685280954666.png", record_pos=(-0.002, -0.505), resolution=(1242, 2208)))
        wait(Template(r"tpl1685280966945.png", record_pos=(0.002, -0.778), resolution=(1242, 2208)))
        touch(Template(r"tpl1685280980933.png", record_pos=(-0.263, -0.63), resolution=(1242, 2208)))
        touch(Template(r"tpl1685280989141.png", record_pos=(-0.409, -0.509), resolution=(1242, 2208)))
        text(user_name)
        sleep(2)
        poco("SecureTextField").click()
        text(password)
        #     poco("SecureTextField").set_text("yuPf172502!")
        wait(Template(r"tpl1685282513910.png", record_pos=(0.01, -0.357), resolution=(1242, 2208)))
